Trapping Functions and Statements Trapping errors while a program is running ------------------------------------------ ON ERROR GOTO line At the module level, causes a program to branch to line, where line refers to either a line number or line label. Branching takes place whenever an error occurs during execution. ON LOCAL ERROR GOTO line At the procedure level, causes a program to branch to line, where line refers to either a line number or line label. Branching takes place whenever an error occurs during execution of the procedure. ON ERROR RESUME NEXT At the module level, causes an implicit error trap, then RESUME NEXT. Returns the error number in ERR. ON LOCAL ERROR RESUME NEXT At the procedure level, causes an implicit error trap, then RESUME NEXT. Returns the error number in ERR. RESUME Returns control to the program after executing an error-handling routine. The program resumes at either the statement causing the error (RESUME), the statement after the one causing the error (RESUME NEXT), or the line identified by line (RESUME line) Getting error-status data ------------------------- ERR Function Returns the code for an error that occurs at run time. ERR Statement Sets ERR to an integer. ERL Returns the number of the line on which an error occurred (if program has line numbers). ERDEV Returns a device-specific error code for the last device (such as a printer) for which the system detected an error. ERDEV$ Returns the name of the last device for which the system detected an error. Defining your own error codes ----------------------------- ERROR Simulates the occurrence of a BASIC error; can also be used to define an error not trapped by BASIC. Trapping events while a program is running ------------------------------------------ ON event GOSUB line Causes a branch to the subroutine starting with line, where line refers either to a line number or line label, whenever event occurs during execution. event ON Enables trapping of event. event OFF Disables trapping of event. event STOP Suspends trapping of event. EVENT ON Enables event trapping. EVENT OFF Disables event trapping. RETURN Returns control to the program after executing an event-handling subroutine. The program resumes at either the statement immediately following the statement that called the subroutine (RETURN), or the line that is identified by line (RETURN line).